package com.pearadmin.pro.modules.stu.rest;

import com.pearadmin.pro.modules.stu.domain.StuOrder;
import com.pearadmin.pro.common.aop.annotation.Log;
import com.pearadmin.pro.common.constant.ControllerConstant;
import com.pearadmin.pro.common.web.base.BaseController;
import com.pearadmin.pro.common.web.domain.Result;
import com.pearadmin.pro.modules.stu.dto.OrderListDto;
import com.pearadmin.pro.modules.stu.param.OrderVo;
import  com.pearadmin.pro.modules.stu.param.StuOrderRequest;
import  com.pearadmin.pro.modules.stu.service.StuOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


/**
 * 订单Controller
 *
 * @author chenJian
 * @date 2021-09-09
 */
@Api(tags = {"订单管理"})
@RestController
@RequestMapping(ControllerConstant.ADMIN+"stu/stuOrder")
public class StuOrderController extends BaseController
{
    @Resource
    private StuOrderService stuOrderService;

    /**
     * 查询订单列表
     *  @param stuOrderRequest 查询参数
     *  @return {@link Result}
     */
    @GetMapping("/page")
    @Log(title = "订单列表")
    @ApiOperation(value = "订单列表")
    public Result<OrderListDto> list(StuOrderRequest stuOrderRequest)
    {
        return success(stuOrderService.page(stuOrderRequest));
    }


    /**
     * 新增保存订单
     * @param vo 查询参数
     * @return {@link Result}
     */
    @PostMapping("/save")
    @Log(title = "新增订单")
    @ApiOperation(value = "新增订单")
    public Result save(@RequestBody OrderVo vo)
    {
        return auto(stuOrderService.addNewOrder(vo));
    }

    /**
     * 查询订单详情
     *
     * @param id 订单ID
     * @return 订单
     */
    @GetMapping("/selectById")
    @Log(title = "查询订单详情")
    @ApiOperation(value = "查询订单详情")
    public Result<StuOrder> selectById(@RequestParam Long id)
    {
        return success(stuOrderService.selectStuOrderById(id));
    }



    /**
     * 修改保存订单
     * @param stuOrder 查询参数
     * @return {@link Result}
     */
    @PutMapping("/update")
    @Log(title = "修改订单")
    @ApiOperation(value = "修改订单")
    public Result update(@RequestBody StuOrder stuOrder)
    {
        return auto(stuOrderService.saveOrUpdate(stuOrder));
    }


    /**
     * 删除保存订单
     * @param id 查询参数
     * @return {@link Result}
     */
    @DeleteMapping("/remove")
    @Log(title = "删除订单")
    @ApiOperation(value = "删除订单")
    public Result remove(@RequestParam Long id)
    {
        return auto(stuOrderService.removeById(id));
    }

    /**
    * 批量删除订单
    * @param ids 批量删除
    * @return {@link Result}
    */
    @DeleteMapping("removeBatch")
    @Log(title = "批量删除订单")
    @ApiOperation(value = "批量删除订单")
    public Result removeBatch(@RequestParam List<Long> ids){
        return auto(stuOrderService.removeByIds(ids));
    }

}
